var a = getApp();

Page({
    data: {
        tabs: [ {
            name: "",
            status: 0,
            orderList: [],
            type: "dividend_alias"
        }, {
            name: "",
            status: 1,
            type: "flat_prize",
            orderList: []
        }, {
            name: "",
            type: "extra_award",
            status: 3,
            orderList: []
        } ],
        customName: {},
        orderData: [],
        isLoadMore: !0,
        page: 1,
        totalPage: 0,
        tabIndex: 0,
        distinction: "balance",
        starTime: null,
        endTime: null,
        diviType: 0,
        finish: 0,
        wait: 0
    },
    onLoad: function(a) {
        var t, e;
        "" === (null !== (t = a.start_time) && void 0 !== t ? t : "") && "" === (null !== (e = a.end_time) && void 0 !== e ? e : "") || this.setData({
            starTime: a.start_time,
            endTime: a.end_time
        }), this.balanceData();
    },
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多了");
    },
    onPullDownRefresh: function() {
        wx.showNavigationBarLoading(), wx.showLoading({
            title: "刷新中..."
        }), this.setData({
            page: 1
        }), this.balanceData();
    },
    balanceData: function() {
        var t = this, e = a.getNetAddresss("plugin.team-analysis.frontend.detail.incomeDetail"), i = {
            start_time: this.data.starTime,
            end_time: this.data.endTime,
            page: this.data.page,
            divi_type: this.data.diviType
        };
        a._getNetWork({
            url: e,
            data: i,
            success: function(a) {
                var e = a.data, i = e.data.data;
                if (console.log(e), wx.hideLoading(), wx.hideNavigationBarLoading(), wx.stopPullDownRefresh(), 
                1 == e.result) {
                    t.data.isLoadMore = !0, t.data.totalPage = e.data.last_page, t.data.totalPage || (t.data.totalPage = 0);
                    var o = e.data.custom_name, n = t.data.tabs;
                    Object.keys(o).forEach(function(a, t) {
                        for (var e in n) n[e].type === a && (n[e].name = o[a]);
                    }), t.setData({
                        orderData: i,
                        finish: e.data.finish,
                        wait: e.data.wait,
                        tabs: n
                    });
                } else t.data.page = t.data.page - 1, t.isLoadMore = !1, wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getMoreData: function() {
        var t = this;
        if (this.isLoadMore = !1, !(this.data.page >= this.data.totalPage)) {
            this.data.page = this.data.page + 1;
            var e = a.getNetAddresss("plugin.team-analysis.frontend.detail.incomeDetail"), i = {
                start_time: this.data.starTime,
                end_time: this.data.endTime,
                page: this.data.page,
                divi_type: this.data.diviType
            };
            a._getNetWork({
                url: e,
                data: i,
                success: function(a) {
                    var e = a.data, i = e.data.data;
                    console.log(e), 1 == e.result ? (t.data.isLoadMore = !0, t.setData({
                        orderData: t.data.orderData.concat(i)
                    })) : (t.data.page = t.data.page - 1, t.isLoadMore = !1, wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1500
                    }));
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        }
    },
    onChange: function(a) {
        this.setData({
            diviType: a.detail.name,
            page: 1
        }), this.balanceData();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onShareAppMessage: function() {}
});